package com.ymatou.iapi.couponservice.testcase;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponservice.parameter.GetPagingUserCouponListBean;
import com.ymatou.iapi.couponservice.parameter.GetPagingUserCouponListReturnData;
import com.ymatou.iapi.couponservice.parameter.UseCouponBean;
import com.ymatou.iapi.couponservice.parameter.UserCouponInfo;
import com.ymatou.iapi.couponservice.service.GetPagingUserCouponListCall;
import com.ymatou.iapi.m.couponservice.parameter.CreateCouponBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.CouponServiceCallService;
import com.ymttest.business.service.CouponServiceMCallService;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.model.YmtCouponProduct;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.database.sqlwapper.YmtCouponProductWapper;
import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.EnvSetup;

@TestSuite
public class Ts_GetPagingUserCouponList {
	private static GetPagingUserCouponListBean getpagingusercouponlistBean;
	private static GetPagingUserCouponListCall getpagingusercouponlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家优惠券列表用例");
	}

	@Before
	public void caseUp() {
		getpagingusercouponlistBean=new GetPagingUserCouponListBean();
		getpagingusercouponlistCall=new GetPagingUserCouponListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getpagingusercouponlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_001() {
		Logger.start(true,"获取买家优惠券列表-码头-不限");
		try {
			  CouponCallService couponCallService = new CouponCallService();

//	            // 平台优惠券
//	            CreateCouponBean createcouponBean =
//	                    couponCallService.setDefaultPlatformLinkCreateCouponBean();
//
//	            List<Integer> country1 = new ArrayList<Integer>();
//	            country1.add(11111);
//	            country1.add(22222);
//
//	            createcouponBean.setCountrys(country1);
//	            
//	            CreateCouponCall call = couponCallService.createPlatformCoupon(createcouponBean);
//	            
//	            couponCallService.receiveCouponInfo(call.getBatchCode(), Integer.parseInt(EnvSetup.getData("couponSellerId")));

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_002() {
		Logger.start(true,"获取买家优惠券列表-码头-未使用");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(1);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_003() {
		Logger.start(true,"获取买家优惠券列表-码头-已过期");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(2);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_004() {
		Logger.start(true,"获取买家优惠券列表-码头-已使用");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(3);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
						
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_005() {
		Logger.start(true,"获取买家优惠券列表-商家-不限");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(2);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_006() {
		Logger.start(true,"获取买家优惠券列表-商家-未使用");
		try {			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(2);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(1);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_007() {
		Logger.start(true,"获取买家优惠券列表-商家-已过期");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(2);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(2);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_008() {
		Logger.start(true,"获取买家优惠券列表-商家-已使用");
		try {

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(2);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(3);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_009() {
		Logger.start(true,"获取买家优惠券列表-验证PageSize起作用");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");
	        
	        GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	        
	        int count=returnData.getRecordCount();
	        List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	        
	        Logger.verifyEquals(1, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(true, count>0, "验证返回UserCouponInfo条数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_010() {
		Logger.start(true,"获取买家优惠券列表-买家ID空");
		try {
			
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	

			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_011() {
		Logger.start(true,"获取买家优惠券列表-买家ID不存在");
		try {
			
			getpagingusercouponlistBean.setBuyerId(99999999);
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");
	        
	        GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	        
	        int count=returnData.getRecordCount();
	        List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	        
	        Logger.verifyEquals(count, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(0, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(0, count, "验证返回UserCouponInfo条数");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_012() {
		Logger.start(true,"获取买家优惠券列表-创建者类型空");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
				
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_013() {
		Logger.start(true,"获取买家优惠券列表-创建者类型不存在");
		try {

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(5);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
				
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");
	        
	        GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	        
	        int count=returnData.getRecordCount();
	        List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	        
	        Logger.verifyEquals(count, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(0, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(0, count, "验证返回UserCouponInfo条数");
	       
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_014() {
		Logger.start(true,"获取买家优惠券列表-优惠券类型空");
		try {
			
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)

			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			 
	        verifyReturn();
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_015() {
		Logger.start(true,"获取买家优惠券列表-优惠券类型不存在");
		try {

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(8);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();				
			
			verifyReturn();
	  
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_016() {
		Logger.start(true,"获取买家优惠券列表-当前页空");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
					
	        verifyReturn();
	        
		} catch (Exception e) {      
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_017() {
		Logger.start(true,"获取买家优惠券列表-当前页不存在");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(999999);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
					
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");
	        
	        GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	        
	        int count=returnData.getRecordCount();
	        List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	  
	        Logger.verifyEquals(0, couponInfos.size(), "验证返回UserCouponInfo条数");
	        Logger.verifyEquals(true, count>0, "验证返回UserCouponInfo条数");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_018() {
		Logger.start(true,"获取买家优惠券列表-每页记录数空");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
				
			Logger.verifyEquals("3", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_019() {
		Logger.start(true,"获取买家优惠券列表-每页记录数不存在");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(-1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
				
			Logger.verifyEquals("3", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_020() {
		Logger.start(true,"获取买家优惠券列表-不限-不限");
		try {

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(0);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(0);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_021() {
		Logger.start(true,"获取买家优惠券列表-码头-过期选项卡中不应该包括已使用的优惠券-JIRACONN-954");
		try {
			
			CouponServiceMCallService couponCallService = new CouponServiceMCallService();
			CouponServiceCallService couponServiceCallService = new CouponServiceCallService();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	

			String platformcouponCode =
                     couponCallService.receiveCouponInfo(couponCallService.createPlatformCoupon(createcouponBean).getBatchCode(), Integer.parseInt(EnvSetup.getData("BuyUserId"))).getUserReceiveResult().getCouponCode();
		        
			UseCouponBean useCouponBean = couponServiceCallService.setUseCouponBean(Integer.parseInt(EnvSetup.getData("BuyUserId")), 12233, platformcouponCode);
			couponServiceCallService.useCoupon(useCouponBean);

			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(2);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");

	       GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	       
	       int count=returnData.getRecordCount();
	       List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	       
	       Logger.verifyEquals(count, couponInfos.size(), "验证返回UserCouponInfo条数");
	       
	       for(int i=0;i<count;i++)
	       {
	    	   UserCouponInfo couponInfo = couponInfos.get(i);
	    	   String couponCode = couponInfo.getCouponCode();
	    	   Logger.verifyEquals(false,couponCode.equals(platformcouponCode),"验证过期选项卡中不应该包括已使用的优惠券");
	       }
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_022() {
		Logger.start(true,"获取买家优惠券列表-商家-过期选项卡中不应该包括已使用的优惠券-JIRACONN-954");
		try {
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(1);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(2);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			verifyReturn();
					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetPagingUserCouponList_023() {
		Logger.start(true,"获取买家优惠券列表-商家-已作废不会出现在 已过期 tab里面 - JIRACONN-4658");
		try {
			
			CouponServiceMCallService couponCallService = new CouponServiceMCallService();
			CouponServiceCallService couponServiceCallService = new CouponServiceCallService();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	

            List<Integer> country1 = new ArrayList<Integer>();
            country1.add(11111);
            country1.add(22222);

            createcouponBean.setCountrys(country1);
            
            String sCouponCode =  couponCallService.receiveCouponInfo(couponCallService.createPlatformCoupon(createcouponBean).getBatchCode(), Integer.parseInt(EnvSetup.getData("BuyUserId"))).getUserReceiveResult().getCouponCode();
		    
            Calendar calendar=Calendar.getInstance();   
            calendar.setTime(createcouponBean.getValidEnd()); 
            System.out.println(calendar.get(Calendar.DAY_OF_MONTH));//今天的日期 
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+1);//让日期加1  
            
            new YmtCouponWapper().setdValidStart(calendar.getTime(), sCouponCode);
            
			getpagingusercouponlistBean.setBuyerId(Integer.parseInt(EnvSetup.getData("couponSellerId")));
			//创建者类型(0:代表不限 1:码头 2:商家)
			getpagingusercouponlistBean.setCreaterType(2);
			//优惠券类型(0:不限 1:未使用 2:已过期 3:已使用)
			getpagingusercouponlistBean.setCouponType(2);
			// 当前页
			getpagingusercouponlistBean.setPageIndex(1);
			// 每页记录数
			getpagingusercouponlistBean.setPageSize(1000);
			
			getpagingusercouponlistCall.setData(getpagingusercouponlistBean);
			getpagingusercouponlistCall.callService();	
			
			Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
	        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");

	       GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
	       
	       int count=returnData.getRecordCount();
	       List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
	       
	       Logger.verifyEquals(count, couponInfos.size(), "验证返回UserCouponInfo条数");
	       
	       for(int i=0;i<count;i++)
	       {
	    	   UserCouponInfo couponInfo = couponInfos.get(i);
	    	   String couponCode = couponInfo.getCouponCode();
	    	   
	    	   Logger.verifyEquals(false, couponCode.equals(sCouponCode), "验证已作废优惠券不会出现在列表中");	    	   
	       }
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	private void verifyReturn() throws ParseException
	{
		Logger.verifyEquals("0", getpagingusercouponlistCall.getStatusCode1(), "验证返回code");
        Logger.verifyEquals("操作成功！", getpagingusercouponlistCall.getMessage(), "验证返回Message");

       GetPagingUserCouponListReturnData returnData=getpagingusercouponlistCall.getPagingUserCouponListReturnData();
       
       int count=returnData.getRecordCount();
       List<UserCouponInfo> couponInfos = returnData.getUserCouponList();
       
       Logger.verifyEquals(count, couponInfos.size(), "验证返回UserCouponInfo条数");
       
       for(int i=0;i<count;i++)
       {
    	   UserCouponInfo couponInfo = couponInfos.get(i);
    	   String couponCode = couponInfo.getCouponCode();
    	   Logger.comment("验证CouponCode为"+couponCode+"记录的正确性。");
    	    Map result = new YmtCouponWapper().selectCouponInfoByCouponCode(couponCode).get(0);
    	    
    	    Logger.verifyEquals(Integer.parseInt(result.get("iScenarioType").toString()), couponInfo.getProductLimitType(),
    				"验证返回字段productLimitType与Ymt_CouponSetting表中iScenarioType一致");
        	
    	    YmtCouponPrivateUserBound ymtCouponPrivateUserBound = new YmtCouponPrivateUserBoundWapper().selectBysCouponCode(couponCode).get(0);
    	    
    	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    	    Logger.verifyEquals(true, isDateEqual(sdf.format(ymtCouponPrivateUserBound.getdAddTime()),
                    couponInfo.getUserReceiveTime()), "验证优惠券UserReceiveTime与数据库相同");
    	    Logger.verifyEquals(Integer.parseInt(ymtCouponPrivateUserBound.getiCouponUsedCount().toString()),
                    couponInfo.getUseRemainTimes(), "验证优惠券UseRemainTimes与数据库相同");

    	    if(getpagingusercouponlistBean.getBuyerId()!=null)
    	    {
    	    	Logger.verifyEquals(getpagingusercouponlistBean.getBuyerId(),
    	    			ymtCouponPrivateUserBound.getiUserId(), "验证BuyerId与数据库相同");
    	    }
    	    else {
    	    	Logger.verifyEquals(0,
        	    		ymtCouponPrivateUserBound.getiUserId(), "验证BuyerId与数据库相同");
			}

    	    Logger.verifyEquals(result.get("sCouponName"),
    	    		couponInfo.getCouponName(), "验证CouponName与数据库相同");
    	    Logger.verifyEquals(result.get("CouponDes"),
    	    		couponInfo.getCouponDes(), "验证CouponDes与数据库相同");
    	    		
            Logger.verifyEquals(true, isDateEqual(result.get("fMinOrderValue"),
                    couponInfo.getMeetAmount()), "验证优惠券MeetAmount与数据库相同");
            Logger.verifyEquals(true, isDateEqual(result.get("fCouponValue"),
                    couponInfo.getDeductionAmount()), "验证优惠券DeductionAmount与数据库相同");

            Logger.verifyEquals(true, isDateEqual(result.get("dValidStart").toString(),
                    couponInfo.getStartTime().toString()), "验证优惠券StartTime与数据库相同");
            Logger.verifyEquals(true, isDateEqual(result.get("dValidEnd").toString(),
                    couponInfo.getEndTime().toString()), "验证优惠券EndTime与数据库相同");
            Logger.verifyEquals(result.get("iUserType"),
                    couponInfo.getUserTypeInfo(), "验证优惠券UserTypeInfo与数据库相同");
            Logger.verifyEquals(true, isContain(result.get("sSellerIds"),
                    couponInfo.getSellerIds()), "验证优惠券SellerIds与数据库相同");

            Logger.verifyEquals(true, isContain(result.get("sProductCategories"),
                    couponInfo.getProductCategories()), "验证优惠券数据库中ProductCategories包含商品指定ProductCategories");
           
            if(result.get("iScenarioType")!=null&&Integer.parseInt(result.get("iScenarioType").toString())==2)
            {
            	 Logger.verifyEquals("product",
                         couponInfo.getSpecificProducts(), "验证优惠券数据库中SpecificProducts包含商品指定SpecificProducts");
            }
           
            Logger.verifyEquals(true, isContain(result.get("sProductBrands"),
                    couponInfo.getProductBrands()), "验证优惠券数据库中ProductBrands包含商品指定ProductBrands");
            Logger.verifyEquals(true, isContain(result.get("sActivityIds"),
                    couponInfo.getActivityIds()), "验证优惠券数据库中ActivityIds与包含商品指定ActivityIds");
            Logger.verifyEquals(true, isContain(result.get("sUsePlatforms"),
                    couponInfo.getUsePlatforms()), "验证优惠券数据库中UsePlatforms包含商品指定UsePlatforms");
            
            Logger.verifyEquals(true, isContain(result.get("sCountrys"),
                    couponInfo.getCountrys()), "验证优惠券数据库中sCountrys包含商品指定Countrys");
           
            if(getpagingusercouponlistBean.getCreaterType()!=null && getpagingusercouponlistBean.getCreaterType()!=0)
            {
            	  Logger.verifyEquals(getpagingusercouponlistBean.getCreaterType(),Integer.parseInt(result.get("iBatchCreateType").toString()), 
            			  "验证CouponDes与数据库相同");
            }
            
            if(getpagingusercouponlistBean.getCouponType()!=null && getpagingusercouponlistBean.getCouponType()!=0)
            {
            	Date now=new Date();
            	DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        		Date endDate =  df.parse(result.get("dValidEnd").toString());
        		
            	if(getpagingusercouponlistBean.getCouponType()==2)
            	{            		
            		Logger.verifyEquals(true,now.after(endDate), 
            			  "验证优惠券状态为2:已过期");
            	}
            	else {
            		if(getpagingusercouponlistBean.getCouponType()==3)
            				Logger.verifyEquals(true,ymtCouponPrivateUserBound.getiCouponUsedCount()<=0, 
              			  "验证优惠券状态为3:已使用");  
            		else {
            			
            			if(getpagingusercouponlistBean.getCouponType()==1)
            			{
                		Logger.verifyEquals(true,ymtCouponPrivateUserBound.getiCouponUsedCount()>0, 
                    			  "验证优惠券状态为1:未使用");
                		Logger.verifyEquals(true,now.before(endDate), 
                  			  "验证优惠券状态为1:未使用");
                		if(result.get("dValidStart")!=null)
                		{
                			//Logger.comment("dValidStart: "+result.get("dValidStart").toString().substring(0,18));
//                			Logger.verifyEquals(true,new Date(result.get("dValidStart").toString().substring(0,18)).before(endDate), 
//                    			  "验证优惠券状态为1:未使用");
                		}
                		if(result.get("bInvalidStatus")!=null)
                		{
                			Logger.verifyEquals("false",result.get("bInvalidStatus").toString(), 
                    			  "验证优惠券状态为1:未使用");
                		}
            			}
            			
    				}
				}
            	
            }
       }
	}
	


	/**
     * 验证src中的串包含dec
     * 
     * @param src
     * @param des
     * @return
     */
    private boolean isContain(Object src, String des)
    {
        if (src == null)
        {
            return true;
        }
        String srcArray[] = src.toString().split(",");
        String desArray[] = des.split(",");

        for (String str : desArray) {
            if (!isStrInArray(srcArray, str))
                return false;
        }
        return true;
    }

    private boolean isStrInArray(String[] src, String des)
    {
        for (String str : src) {
            if (str.equals(des))
                return true;
        }
        return false;
    }

    private boolean isDateEqual(String str1, String str2)
    {
//    	Date d1=new Date(str1);
//    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
//		// public final String format(Date date)
//    	str1= sdf.format(d1);
//    	Logger.comment("传入str1:|"+str1+"|("+str1.length()+"),str2:|"+str2+"|("+str2.length()+")");
        str1 = str1.trim().substring(0, 19);
        str2 = str2.trim().substring(0, 19).replace("T", " ");
//        Logger.comment("比较str1:|"+str1+"|,str2:|"+str2+"|");
        return str1.equals(str2);
    }
    
    private boolean isDateEqual(Date str1, String str2)
    {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		// public final String format(Date date)
    	String str= sdf.format(str1);
    	Logger.comment("传入str1:|"+str1+"|("+str.length()+"),str2:|"+str2+"|("+str2.length()+")");
    	str = str.trim().substring(0, 19);
        str2 = str2.trim().substring(0, 19).replace("T", " ");
        Logger.comment("比较str:|"+str+"|,str2:|"+str2+"|");
        return str.equals(str2);
    }
    
	 private boolean isDateEqual(Object str1, BigDecimal str2)
     {
		 boolean flag =false;
         BigDecimal str3 = new BigDecimal(str1.toString());
         if(str3.compareTo(str2) == 0)
         {
        	 flag=true;
         }
         else {
			Logger.comment("比较：|"+str1+"|"+str2+"|");
		}
         
         return flag;
     }
}
